﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using BLL;
using Model;
using Tools;


namespace BWAPUI.Controllers
{
    public class LoginController : Controller
    {
        //
        // GET: /Login/

        public ActionResult Index()
        {
            return View();
        }
        [HttpPost]
        public ActionResult Index(UserInfo user)
        {

            UserInfo users = ManageUserBLL.LoginUser(user.LoginName, user.UserPwd);
            if (users != null)
            {
                Session["user"] = users;
                return RedirectToAction("Index", "Home");
            }
            else
            {
                return View();
            }

        }
        public ActionResult register()
        {
            return View();
        }
        [HttpPost]
        public ActionResult register(UserInfo user, string pwd, string LoginName)
        {
            if (pwd == user.UserPwd)
            {
                if (LoginName == user.UserName)
                {
                    ViewBag.us = "用户名存在";
                    return View();
                }

                else
                {
                    ManageUserBLL.register(user);
                    return RedirectToAction("Index");
                }

            }
            else
            {

                ViewBag.error = "两次密码不一致";
            }
            return View();
        }
    }
}
